public class JumpTwo {
    public static void main(String[] args) {
        int[] nums = new int[] {2,3,1,1,4};
        System.out.println(jump(nums));
    }
    public static int jump(int[] nums) {
        //跳跃次数
        int count = 0;
        //最大下标(长度)
        int max = 0;
        //边界下标
        int end= 0;
        if(nums[0] == nums.length-1) {
            return 0;
        }
        for (int i = 0; i < nums.length-1; i++) {
            //每次跳跃就记一次跳跃次数
            //跳跃过后要留下最大位置
            if(max < i+nums[i]) {
                max = i+nums[i];
            }
            if(i == end) {
                end = max;
                count++;
            }
        }
        return count;
    }
}
